package com.ruoyi.web.controller.house;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.data.MD5;
import com.ruoyi.door.domain.HouseDoorT;
import com.ruoyi.infoQuery.domain.HouseDoorInfoQuery;
import com.ruoyi.infoQuery.service.IHouseDoorInfoQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 户信息修改查询Controller
 * 
 * @author ruoyi
 * @date 2023-04-25
 */
@RestController
@RequestMapping("/house/infoQuery")
public class HouseDoorInfoQueryController extends BaseController
{
    @Autowired
    private IHouseDoorInfoQueryService houseDoorInfoQueryService;

    /**
     * 查询户信息修改查询列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HouseDoorInfoQuery houseDoorInfoQuery) throws Exception {
        startPage();
        List<HouseDoorInfoQuery> list = houseDoorInfoQueryService.selectHouseDoorInfoQueryList(houseDoorInfoQuery);
        for(HouseDoorInfoQuery houseDoorInfo:list){
            houseDoorInfo.setUserName(MD5.decrypt(houseDoorInfo.getUserName()));
            houseDoorInfo.setPapersCode(MD5.decrypt(houseDoorInfo.getPapersCode()));
            houseDoorInfo.setTel(MD5.decrypt(houseDoorInfo.getTel()));
            houseDoorInfo.setUserNamePre(MD5.decrypt(houseDoorInfo.getUserNamePre()));
            houseDoorInfo.setPapersCodePre(MD5.decrypt(houseDoorInfo.getPapersCodePre()));
            houseDoorInfo.setTelPre(MD5.decrypt(houseDoorInfo.getTelPre()));
        }
        return getDataTable(list);
    }

    /**
     * 导出户信息修改查询列表
     */
    @Log(title = "户信息修改查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseDoorInfoQuery houseDoorInfoQuery) throws Exception {
        List<HouseDoorInfoQuery> list = houseDoorInfoQueryService.selectHouseDoorInfoQueryList(houseDoorInfoQuery);
        for(HouseDoorInfoQuery houseDoorInfo:list){
            houseDoorInfo.setUserName(MD5.decrypt(houseDoorInfo.getUserName()));
            houseDoorInfo.setPapersCode(MD5.decrypt(houseDoorInfo.getPapersCode()));
            houseDoorInfo.setTel(MD5.decrypt(houseDoorInfo.getTel()));
            houseDoorInfo.setUserNamePre(MD5.decrypt(houseDoorInfo.getUserNamePre()));
            houseDoorInfo.setPapersCodePre(MD5.decrypt(houseDoorInfo.getPapersCodePre()));
            houseDoorInfo.setTelPre(MD5.decrypt(houseDoorInfo.getTelPre()));
        }
        ExcelUtil<HouseDoorInfoQuery> util = new ExcelUtil<HouseDoorInfoQuery>(HouseDoorInfoQuery.class);
        util.exportExcel(response, list, "户信息修改查询数据");
    }


    /**
     * 获取户信息修改查询详细信息
     */
    @GetMapping(value = "/{infoId}")
    public AjaxResult getInfo(@PathVariable("infoId") Long infoId)
    {
        return AjaxResult.success(houseDoorInfoQueryService.selectHouseDoorInfoQueryByInfoId(infoId));
    }

}
